﻿using System;

using Fuse8.DomainFramework.Common;

using Fuse8.ContentManagementFramework.SystemFacade.Exceptions;

namespace Fuse8.ContentManagementFramework.SystemFacade.Workflow
{
    [Serializable]
    public abstract class CmsWorkflowStateTransition
    {
        public abstract int TransitionId { get; }

        public abstract string TransitionTitle { get; }
        
        public virtual void Run(CmsWorkflowState fromState, CmsWorkflowState toState)
        {
            Guard.ArgumentNotNull(fromState, "fromState");
            Guard.ArgumentNotNull(toState, "toState");

            if (fromState.Equals(toState))
            {
                throw new WorkflowException(string.Format("From state {0} is the same as To state {1}", fromState.StateName, toState.StateName));
            }
        }

        public override bool Equals(object obj)
        {
            Guard.ArgumentNotNull(obj, "obj");

            return TransitionId.Equals((obj as CmsWorkflowStateTransition).TransitionId);
        }

        public override int GetHashCode()
        {
            return TransitionId.GetHashCode();
        }
    }
}
